const Router = require('koa-router');
const router = new Router();

// 验证身份
const {authMiddleware, authorizeAdmin} = require('../middlewares/authMiddleware');
// 业务层
const {
  createTransaction,
  getAllTransactions,
  getTransactionById,
  updateTransaction,
  deleteTransaction,
  getUserTransactions,
  deleteUserTransaction,
} = require('../controllers/transactionController')

// 创建交易
router.post('/', authMiddleware, createTransaction);

// 获取所有交易
router.get('/', authMiddleware, authorizeAdmin, getAllTransactions);

// 获取特定交易
router.get('/:id', authMiddleware, authorizeAdmin, getTransactionById);

// 更新交易
router.put('/:id', authMiddleware, authorizeAdmin, updateTransaction);

// 删除交易
router.delete('/:id', authMiddleware, authorizeAdmin, deleteTransaction);

// 获取用户自己的交易记录
router.get('/me', authMiddleware, getUserTransactions);

// 用户删除自己的交易
router.delete('/me/:id', authMiddleware, deleteUserTransaction);

module.exports = router;
